package com.bot.rf.excel;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.bot.rf.entity.BookInfo;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

/**
 * @program: report-form-demo
 * @description: 正常图书Excel模板
 * @author: zyy
 * @create: 2021-02-25 14:32
 **/

@ContentRowHeight(18)
@HeadRowHeight(18)
@HeadFontStyle(fontHeightInPoints = 11, fontName = "等线")
@HeadStyle(horizontalAlignment = HorizontalAlignment.LEFT)
public class BookExcel implements Comparable {

    /**
     * tagId
     */
    @ColumnWidth(30)
    @ExcelProperty("tagId")
    private String tagId;

    /**
     * 条形码
     */
    @ColumnWidth(20)
    @ExcelProperty("条形码")
    private String barcode;

    /**
     * 书名
     */
    @ColumnWidth(50)
    @ExcelProperty("书名")
    private String bookName;

    /**
     * 索书号
     */
    @ColumnWidth(20)
    @ExcelProperty("索书号")
    private String bookIndex;

    /**
     * 楼层
     */
    @ColumnWidth(5)
    @ExcelProperty("楼层")
    private String floor;

    /**
     * 盘点层架标
     */
    @ColumnWidth(20)
    @ExcelProperty("盘点层架标")
    private String shelf;

    /**
     * 层架标代码
     */
    @ColumnWidth(20)
    @ExcelProperty("层架标代码")
    private String shelfCode;

    /**
     * 数据库代码
     */
    @ColumnWidth(20)
    @ExcelProperty("数据库代码")
    private String databaseCode;

    /**
     * 是否错架
     */
    @ColumnWidth(10)
    @ExcelProperty("是否错架")
    private String errorShelf;


    /**
     * 是否错架
     */
    @ColumnWidth(13)
    @ExcelProperty("原始馆藏状态")
    private String bookStatus;


    /**
     * 是否错架
     */
    @ColumnWidth(13)
    @ExcelProperty("是否馆藏错误")
    private String errorStatus;

//    /**
//     * 序号
//     */
//    @ColumnWidth(10)
//    @ExcelProperty("序号")
//    private String orderNo;
//
//    /**
//     * 总数
//     */
//    @ColumnWidth(10)
//    @ExcelProperty("总数")
//    private String total;

    public String getTagId() {
        return tagId;
    }

    public void setTagId(String tagId) {
        this.tagId = tagId;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getBookIndex() {
        return bookIndex;
    }

    public void setBookIndex(String bookIndex) {
        this.bookIndex = bookIndex;
    }

    public String getFloor() {
        return floor;
    }

    public void setFloor(String floor) {
        this.floor = floor;
    }

    public String getShelf() {
        return shelf;
    }

    public void setShelf(String shelf) {
        this.shelf = shelf;
    }

//    public String getOrderNo() {
//        return orderNo;
//    }
//
//    public void setOrderNo(String orderNo) {
//        this.orderNo = orderNo;
//    }
//
//    public String getTotal() {
//        return total;
//    }
//
//    public void setTotal(String total) {
//        this.total = total;
//    }

    public String getShelfCode() {
        return shelfCode;
    }

    public void setShelfCode(String shelfCode) {
        this.shelfCode = shelfCode;
    }

    public String getErrorShelf() {
        return errorShelf;
    }

    public void setErrorShelf(String errorShelf) {
        this.errorShelf = errorShelf;
    }

    public String getDatabaseCode() {
        return databaseCode;
    }

    public void setDatabaseCode(String databaseCode) {
        this.databaseCode = databaseCode;
    }

    public String getBookStatus() {
        return bookStatus;
    }

    public void setBookStatus(String bookStatus) {
        this.bookStatus = bookStatus;
    }

    public String getErrorStatus() {
        return errorStatus;
    }

    public void setErrorStatus(String errorStatus) {
        this.errorStatus = errorStatus;
    }

    public BookExcel(BookInfo bookInfo, String floor, String shelf, String shelfCode, String errorFlag) {
        this.barcode = bookInfo.getBarcode();
        this.floor = floor;
        this.shelf = shelf;
        this.shelfCode = shelfCode;
//        this.orderNo = bookInfo.getLocation().getOrderNo() + "";
//        this.total = bookInfo.getLocation().getTotalNum() + "";
        this.bookName = bookInfo.getBookName();
        this.bookIndex = bookInfo.getBookIndex();
        this.tagId = bookInfo.getTagId();
        this.errorShelf = errorFlag;
        this.databaseCode = bookInfo.getTemporaryLocationName();
        this.bookStatus = handleBookStatus(bookInfo.getProcessType());
        this.errorStatus = handelErrorStatus(bookInfo.getProcessType());
    }
    public String handelErrorStatus(String index){
        return ("0".equals(index) ? "正确":"错误");
    }
    public String handleBookStatus(String index){
        // 异常图书，状态是空的，不算馆藏错误
        if (index == null || index == ""){
            index = "";
        }
        switch (index) {
            case "0":
                return "在架";
            case "1":
                return "借出";
            case "2":
                return "剔除";
            case "3":
                return "编目";
            default:
                return "";
        }
    }

    @Override
    public String toString() {
        return "ExportBookExcel{" +
                "barcode='" + barcode + '\'' +
                ", floor='" + floor + '\'' +
                ", shelf='" + shelf + '\'' +
//                ", orderNo='" + orderNo + '\'' +
//                ", total='" + total + '\'' +
                ", bookName='" + bookName + '\'' +
                ", bookIndex='" + bookIndex + '\'' +
                ", tagId='" + tagId + '\'' +
                '}';
    }

    /**
     * 重写比较逻辑
     * 楼层 > 层架标 > 序号
     * @param o
     * @return
     */
    @Override
    public int compareTo(Object o) {
        BookExcel bookExcel = (BookExcel) o;
        int res;
        if (floor.equals(bookExcel.floor)) {
            if (shelf.equals(bookExcel.shelf)) {
                if (bookIndex.equals(bookExcel.bookIndex)){
                    res = 0;
                }else {
                    res = bookIndex.compareTo(bookExcel.bookIndex);
                }
            } else {
                res = shelf.compareTo(bookExcel.shelf);
            }
        } else {
            res = floor.compareTo(bookExcel.floor);
        }
        return res;
    }
}
